# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms.dwd.tab.dwd_tab_barscan_loading_base_dt import jms_dwd__dwd_tab_barscan_loading_base_dt
from jms.dim.dim_lmdm_sys_network import jms_dim__dim_lmdm_sys_network
from jms.ods.mysql.registration_problem_piece import jms_ods__registration_problem_piece
from jms.ods.tab.tab_end_piece import jms_ods__tab_end_piece
from jms.dwd.tab.dwd_tab_barscan_arrival_base_dt import jms_dwd__dwd_tab_barscan_arrival_base_dt
from jms.dwd.tms.dwd_tmsnew_shipment_union_base_dt import jms_dwd__dwd_tmsnew_shipment_union_base_dt
from jms.ods.tms.yl_tms_branch_time_effective import jms_ods__yl_tms_branch_time_effective

jms_dm__dm_tab_day_recevie_total_dt = SparkSqlOperator(
    task_id='jms_dm__dm_tab_day_recevie_total_dt',
    email=['rongguangfan@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_tab_day_recevie_total_dt_{{ execution_date | cst_ds_nodash }}',
    sql='jms/dm/dm_tab_day_recevie_total_dt/execute.hql',
    pool_slots=5,
    executor_cores=3,
    executor_memory='4G',
    driver_memory='4G',
    num_executors=10,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          #'spark.dynamicAllocation.maxExecutors': 30,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.maxExecutors': 25,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.executor.memoryOverhead': '2G',  # 堆外内存
          'spark.sql.autoBroadcastJoinThreshold': 104857600,  # MapJoin 阈值 100M
          'spark.sql.shuffle.partitions': 300,
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 180,  # 每天生成 20 个分区
              'hive.exec.max.dynamic.partitions.pernode': 180,  # 每天生成 20 个分区
              },
    yarn_queue='pro',
    execution_timeout=timedelta(minutes=60),
)

jms_dm__dm_tab_day_recevie_total_dt << [jms_dwd__dwd_tab_barscan_loading_base_dt,
                                        jms_dim__dim_lmdm_sys_network,
                                        jms_ods__registration_problem_piece,
                                        jms_ods__tab_end_piece,
                                        jms_dwd__dwd_tab_barscan_arrival_base_dt,
                                        jms_dwd__dwd_tmsnew_shipment_union_base_dt,
                                        jms_ods__yl_tms_branch_time_effective ]
